Shader "Custom/URPLitPerPixelHalfLambert"
{
    Properties
    { 
        [MainColor] _BaseColor("Base Color", Color) = (1, 1, 1, 1)
    }

    SubShader
    {
        Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" }

        Pass
        {
            Tags { "LightMode" = "UniversalForward" }
            
            HLSLPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

            CBUFFER_START(UnityPerMaterial)
                half4 _BaseColor;
            CBUFFER_END
            
            struct Attributes
            {
                float4 positionOS   : POSITION;
                half3 normal : NORMAL;
            };

            struct Varyings
            {
                float4 positionHCS  : SV_POSITION;
                half3 normal : NORMAL;
            };

            Varyings vert(Attributes IN)
            {
                Varyings OUT;
                
                half3 normalWorld = TransformObjectToWorldNormal(IN.normal);

                OUT.positionHCS = TransformObjectToHClip(IN.positionOS.xyz);
                OUT.normal = normalWorld;
                
                return OUT;
            }

            half4 frag(Varyings IN) : SV_Target
            {
                half3 lightPosWorld = _MainLightPosition.xyz;
                half4 ambient = unity_AmbientGround;
                half4 diffuse = _MainLightColor * _BaseColor * saturate(dot(IN.normal, lightPosWorld) * 0.5 + 0.4);
                return ambient + diffuse;
            }
            ENDHLSL
        }
    }
}